package artid.com.arttogoa;

import java.util.List;

import artid.com.arttogoa.R;
import artid.com.arttogoa.adapter.LogisticsInfo_Adapter;
import artid.com.arttogoa.barcode.Cache;
import artid.com.arttogoa.parser.LogisticsInfoParser;
import artid.com.arttogoa.util.MyListView_Util;
import artid.com.arttogoa.volley.VolleyBasic;
import artid.com.arttogoa.volley.VolleyCallback;
import artid.com.arttogoa.volley.VolleyData;
import artid.com.arttogoa.volley.VolleyMap;
import com.android.volley.VolleyError;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

/**
 * 
 *    
 * 项目名称：ArtworkArtA   
 * 类名称   ：LogisticsInfo_Activity   
 * 类描述   ：物流信息   
 * 创建人   ：耿卫斌   
 * 创建时间：2016-7-27 上午10:30:03   
 *
 */
public class LogisticsInfo_Activity extends BaseActivity implements OnClickListener{
	private Context mContext;
	private ScrollView mScrollView;
	private MyListView_Util mListView;
	private LinearLayout noDataLL;
	private TextView waybillNum,noData_hint;
	private LogisticsInfo_Adapter adapter;
	private String shipping_code;//物流单号
	private String order_id;//订单id
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_logisticsinfo);
		mContext=LogisticsInfo_Activity.this;
		setContent(this, getIntent());
		initView();
	}

	private void initView(){
		mTittle.setText("物流信息");
		setBack();
		shipping_code=getIntent().getStringExtra("shipping_code");
		order_id=getIntent().getStringExtra("order_id");
		noDataLL=(LinearLayout) findViewById(R.id.include_noDataLL);
		noData_hint=(TextView) findViewById(R.id.include_noData_hint);
		noData_hint.setText("暂时还没有该商品的物流信息哦！");
		mScrollView=(ScrollView) findViewById(R.id.LogisticsInfo_scrollView);
		mScrollView.smoothScrollTo(0,0);   
		mListView=(MyListView_Util) findViewById(R.id.LogisticsInfo_ListView);
		waybillNum=(TextView) findViewById(R.id.LogisticsInfo_waybillNum);
		waybillNum.setText(shipping_code);
		getData(order_id);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}

	/**
	 * 获取物流信息
	 */
	private void getData(String order_id){
		VolleyBasic.getInstance(this).post(Cache.logistics,
				VolleyMap.getInstance().logistics(order_id),
				LogisticsInfoParser.class, new VolleyCallback() {

			@SuppressWarnings("unchecked")
			@Override
			public void onSuccess(VolleyData vd) {
				// TODO Auto-generated method stub
				System.out.println(vd.getJson());
				List<LogisticsInfoParser> list= (List<LogisticsInfoParser>) vd.getList();
				if(list!=null && list.size()!=0){
					adapter=new LogisticsInfo_Adapter(mContext,list);
					mListView.setAdapter(adapter);
					noDataLL.setVisibility(View.GONE);
				}else{
					noDataLL.setVisibility(View.VISIBLE);
				}
			}

			@Override
			public void onError(VolleyError volleyError) {
				// TODO Auto-generated method stub

			}
		});
	}
}
